﻿@model PagedList.IPagedList<OMS.Models.ItemModelView>           

@using OMS.Models

@{
    ViewBag.Title = "AddItem";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#item_table tbody tr').click(function () {
            $('#item_table').css('background-color', '#fff');
            $(this).css('background-color', '#abc');
            var id = $(this).find("#item_Id").attr("value");
            var name = $(this).find("#item_Name").text();
            var price = $(this).find("#item_Price").attr("value");
            $('#item_description #item_id').attr('value', id);
            $('#item_description #item_name').text(name);
            $('#item_description #item_price').text(price);
        });
    });
</script>

<h2>AddItem</h2>

<form method=get>
    @Html.Hidden("orderId", new { @ViewBag.OrderId })
    @Html.DropDownList("filterBy", new SelectList(new string[] {"name","description"}, ViewBag.FilterBy))
    @Html.TextBox("SearchString")
    <input type="submit"/>
</form>

<table align=center id="item_table">
<tr>
    <th>Name</th>
    <th>Description</th>
    <th>Quantity</th>
    <th>Price</th>
</tr>
@foreach (var item in Model)
{
    <tr>
        @Html.HiddenFor(i => item.Id)
        <td id="item_Name">
            @Html.DisplayFor(i => item.Name)
        </td>
        <td id="item_Description">
            @Html.DisplayFor(i => item.Description)
        </td>
        <td>
            @Html.DisplayFor(i => item.Quantity)
        </td>
        <td>
            @Html.DisplayFor(i => item.Price) 
        </td>
        @Html.HiddenFor(i => item.Price) 
    </tr>
}
</table>

<br />

<div align=center>
    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
    of @Model.PageCount
     
    @if (Model.HasPreviousPage)
    {
        @Html.ActionLink("First", "AddItem", new { orderId = ViewBag.OrderId, filterBy = ViewBag.FilterBy,
            searcgString = ViewBag.SearchString, page = 1 })
        @Html.Raw(" ");
        @Html.ActionLink("< Prev", "AddItem", new { orderId = ViewBag.OrderId, filterBy = ViewBag.FilterBy,
            searcgString = ViewBag.SearchString, page = Model.PageNumber - 1 })
    }
    else
    {
        @:First
        @Html.Raw(" ");
        @:< Prev
    }
     
    @if (Model.HasNextPage)
    {
        @Html.ActionLink("Next >", "AddItem", new {  orderId = ViewBag.OrderId, filterBy = ViewBag.FilterBy,
            searcgString = ViewBag.SearchString,page = Model.PageNumber + 1 })
        @Html.Raw(" ");
        @Html.ActionLink("Last", "AddItem", new {  orderId = ViewBag.OrderId, filterBy = ViewBag.FilterBy,
            searcgString = ViewBag.SearchString, page = Model.PageCount })
    }
    else
    {
        @:Next >
        @Html.Raw(" ")
        @:Last
    }
</div>

<br />

@using (@Html.BeginForm("AddItem", "Customer", new { orderId = @ViewBag.OrderId }, FormMethod.Post))
{
    <input name="order_id" type=hidden value=@ViewBag.OrderId></input>
    <table id="item_description" align=center>
        <input name="item_id" id="item_id" type=hidden></input>
        <tr>
            <td>Name</td>
            <td id="item_name"></td>
        </tr>
        <tr>
            <td>Price</td>
            <td id="item_price"></td>
        </tr>
        <tr>
            <td>Quantity</td>
            <td>@Html.Editor("quantity")</td>
        </tr>
        <tr>
            <td>Dimension</td>
            <td>
                <select name="dimension">
                    <option value="item" selected>Item</option>
                    <option value="box">Box</option>
                    <option value="package">Package</option>
                </select>
            </td>
        </tr>
    </table>
    <button>Remove</button>
    <button action=submit>Done</button>
    @Html.ActionLink("Cancel", "EditOrder", new { id = @ViewBag.OrderId })
}
</form>